package com.xuyuan.json.jackson.polymorphic;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;

public class JacksonTest {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        JacksonProduct jacksonProduct = new JacksonProduct();
        JacksonProduct1 jacksonProduct1 = new JacksonProduct1();
        jacksonProduct1.setName("json1");
        JacksonProduct2 jacksonProduct2 = new JacksonProduct2();
        jacksonProduct2.setName("json2");
        List<JacksonParent> list = new ArrayList<>();
        list.add(jacksonProduct1);
        list.add(jacksonProduct2);
        jacksonProduct.setJacksonProduct(list);
        String s = objectMapper.writeValueAsString(jacksonProduct);
        System.out.println("序列化成字符串：" + s);
        System.out.println("转换后的实体类结果：");
        System.out.println(objectMapper.readValue(s, JacksonProduct.class));
    }
}
